package com.carrental.api.oms.controller;


import com.carrental.common.response.CommonPage;
import com.carrental.common.response.CommonResult;
import com.carrental.api.common.query.CommonQueryParam;
import com.carrental.api.oms.domain.OmsLendCheck;
import com.carrental.api.oms.domain.bo.OmsLendCheckPost;
import com.carrental.api.oms.service.IOmsLendCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 梁毅
 * @since 2022-03-07 23:12:02
 */
@RestController
@Api(tags = "出车检查单管理")
@RequestMapping("/api/serve/lend-check")
public class OmsLendCheckController {
    @Autowired
    private IOmsLendCheckService lendCheckService;

    @PostMapping()
    @ApiOperation("生成出车检查单")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> lendCheckCreate(@RequestBody OmsLendCheckPost lendCheck) {
        return CommonResult.success(lendCheckService.create(lendCheck));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除出车检查单信息")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> lendCheckRemove(@PathVariable Long id) {
        return CommonResult.success(lendCheckService.delete(id));
    }

    @PutMapping("/{id}")
    @ApiOperation("修改出车检查单信息")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> lendCheckUpdate(@ApiParam(name = "id", value = "检查单标识", required = true)
                                                 @PathVariable Long id, @RequestBody OmsLendCheckPost lendCheck) {
        return CommonResult.success(lendCheckService.update(id,lendCheck));
    }

    @GetMapping()
    @ApiOperation("获取出车检查单列表")
    public CommonResult<List<OmsLendCheck>> lendCheckList(CommonQueryParam commonQueryParam) {
        return CommonResult.success(lendCheckService.list(commonQueryParam));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取出车检查单详情")
    public CommonResult<OmsLendCheck> lendCheckObj(@ApiParam(name = "id", value = "检查单标识", required = true)
                                                   @PathVariable Long id) {
        return CommonResult.success(lendCheckService.detail(id));
    }

    @GetMapping("/page")
    @ApiOperation("获取出车检查单分页")
    public CommonResult<CommonPage<OmsLendCheck>> lendCheckPage(CommonQueryParam commonQueryParam) {
        return CommonResult.success(CommonPage.restPage(lendCheckService.pageList(commonQueryParam)));
    }
}
